<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.finance.ExpenseHq"%>
<%@ page import="com.onlineMIS.common.Common_util"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>
<script>

var costType = 0;
var incomeType = 1;

var dataGrid ;
$(document).ready(function(){
	parent.$.messager.progress('close'); 
	$("#type").combobox('setValue',<%=Common_util.ALL_RECORD%>);
	
	var params = $.serializeObject($('#expenseForm')); 

	dataGrid = $('#dataGrid').datagrid({
		url : 'financeHQJSON!searchExpense',
		queryParams: params,
		fit : true,
		border : false,
		pagination : true,
		pageSize : 15,
		pageList : [ 15, 30],		
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		nowrap : false,	
		rowStyler: function(index,row){
			var style = "";
			if (row.status == STATUS_CANCEL)
				style += 'color:red;';
			else if (row.status == STATUS_DRAFT)
					style += 'color:blue;';
					
			return style;
		},
		rownumbers : true,
		sortName : 'status',
		sortOrder : 'asc',
		columns : [ [ 
			{
				field : 'id',
				title : '单据号',
				width : 50
			},{
				field : 'financeCategoryName',
				title : '支出机构',
				width : 140
			},{
				field : 'amount',
				title : '金额',
				width : 80
			}, {
				field : 'userName',
				title : '转账人员',
				width : 80
			},{
				field : 'comment',
				title : '备注',
				width : 140
			},{
				field : 'feeType',
				title : '单据类型',
				width : 110,
				align: 'center',
				formatter :  function(value, row, index) {
					if(row.id == 0){
						var str = "";
					}else if(row.feeType == <%=ExpenseHq.DOCUMENT_TYPE_HQ_COST%>){
						var str = $.formatString('<button class="button">费用单</button>');
					}else if(row.feeType == <%=ExpenseHq.DOCUMENT_TYPE_HQ_INCOME%>){
						var str = $.formatString('<button class="button1">收益单</button>');
					}
					return str;
				}
			},{
				field : 'belongTo',
				title : '单据归属',
				width : 110,
				align: 'center'
			},  {
				field : 'statusS',
				title : '状态',
				width : 80,
				sortable:true,
				order:'desc'
			}, {
				field : 'expenseDate',
				title : '单据日期',
				width : 100,
				sortable:true,
				order:'desc'
			}, {				
				field : 'createDate',
				title : '创建时间',
				width : 120,
				sortable:true,
				order:'desc'
			}, {
				field : 'lastUpdateDate',
				title : '最后一次修改时间',
				width : 120
			},  {			    
				field : 'delete',
				title : '删除',
				width : 80,
				align:'center',
				formatter : function(value, row, index) {
					
					var str = '';
					
					if (row.status == STATUS_DRAFT){
						str += $.formatString('<a href="#" onclick="deleteExpense(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="删除账目"/></a>', row.id,row.status,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/delete.png');
						
					}
					    return str;
				}
			}, {			    
				field : 'details',
				title : '详情',
				width : 80,
				align:'center',
				formatter : function(value, row, index) {
					
					var str = '';
					var url = 'financeHQJSP!editExpense?formBean.expenseHq.id=' + row.id;
						if(row.feeType == costType){							
							str += $.formatString('<a href="#" onclick="addTab6(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="编辑账目"/></a>',url,'费用单据详情' + row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');						
						
						    return str;
						}else if(row.feeType == incomeType){						
							str += $.formatString('<a href="#" onclick="addTab6(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="编辑账目"/></a>',url,'收益单据详情' + row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');						
						
						    return str;
						}
						
				}
			}  , {			    
				field : 'copy',
				title : '复制',
				width : 80,
				align:'center',
				formatter : function(value, row, index) {						
					return $.formatString('<a href="#" onclick="copyExpense(\'{0}\');"><img border="0" src="{1}" /></a>', row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/copy4.png');						
				}						
				
			}   
		   ]],
			toolbar : '#toolbar',	
			onLoadSuccess: function(data) {
		        var tr = $(this).datagrid('getPanel').find('div.datagrid-body tr');
		        tr.each(function() {
		            $(this).children('td').children('div').css('height', '32px');
		        });
		    	 // 设置数据行垂直居中
		        $(this).datagrid('getPanel').find('.datagrid-body .datagrid-cell').css({
		            'display': 'flex',
		            'align-items': 'center'
		        });
		    }
	});
});

/**
 * 删除记录
 */
function deleteExpense(id,status){
	$.messager.confirm('确认','您确认想要删除此条记录吗？',function(r){
	    if (r){	   
	        var params = "formBean.expenseHq.id=" +id +"&formBean.expenseHq.status=" + status;
		    $.post("<%=request.getContextPath()%>/action/financeHQJSON!deleteExpense",params, confirmIsDelete,"json");	
	    }
	});
}

/**
 * 复制记录
 */
function copyExpense(orderId){
	$.messager.confirm('确认','您确认想要复制此条记录吗？',function(r){
	    if (r){	   
	        var params = "formBean.expenseHq.id=" +orderId;
		    $.post("<%=request.getContextPath()%>/action/financeHQJSON!copyExpense",params, confirmIsDelete,"json");	
	    }
	});
}


function confirmIsDelete(data){
	if(data != null){
		var returnCode = data.returnCode;
		if (returnCode === 3){
			 $.messager.alert('提示',data.message,'error');
		}else{			
			genSalesReport();
		}
		
	}
						
}

function genSalesReport(){
	dataGrid.datagrid('load', $.serializeObject($('#expenseForm')));
}

function downloadExpenseHqDetails(){
	document.expenseForm.action="financeHQJSP!downloadExpenseHqDetails";
	document.expenseForm.submit();
}
</script>
</head>
<body>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'north',border:false" style="height: 95px;">
	<s:form id="expenseForm" name="expenseForm"
		theme="simple" method="POST">
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="50" colspan="7">
								<div class="errorAndmes">
									<s:actionerror cssStyle="color:red" />
									<s:actionmessage cssStyle="color:blue" />
								</div>
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="35" colspan="10">总部财务费用单据:
										</td>
									</tr>
									<tr class="InnerTableContent" height="30">						
										<td width="5%" align="center"><strong>单据日期:</strong></td>
										<td width="15%" ><s:textfield id="startDate"
											name="formBean.searchStartTime" cssClass="easyui-datebox"
											data-options="width:100,editable:false" /> &nbsp;至&nbsp; <s:textfield
											id="endDate" name="formBean.searchEndTime" cssClass="easyui-datebox"
											data-options="width:100,editable:false" /></td>

										<td width="4%" align="center"><strong>状态:</strong></td>
										<td width="13%"><s:select id="status"  cssClass="easyui-combobox" name="formBean.expenseHq.status" list="formBean.expenseHq.statusMap" listKey="key" listValue="value" headerKey="-1" headerValue=""  data-options="prompt:'请选择状态',width:170,editable:false"/></td>
										<td width="4%" align="center"><strong>类型:</strong></td>
										<td width="13%"><s:select id="type"  cssClass="easyui-combobox" name="formBean.expenseHq.type" list="formBean.expenseHq.typeMap" listKey="key" listValue="value" headerKey="-1" headerValue=""  data-options="prompt:'请选择类型',width:170,editable:false"/></td>
										<td width="4%" align="center"><strong>账目 :</strong></td>
										<td width="13%"><s:select name="formBean.expenseHq.financeCategory.id" headerKey="-1"
											headerValue=""  data-options="prompt:'请选择账目',width:100,editable:false"
											cssClass="easyui-combobox" style="width:170px;"
											list="uiBean.financeCategory" listKey="id" listValue="itemName" /></td>		
										<td width="4%" align="center"><strong>单据号:</strong></td>
										<td ><input class="easyui-textbox" style="width:140px"  data-options="prompt:'请输入单据号'"   id="expenseHqId" name="formBean.expenseHq.id" size="20"></input></td>	
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</s:form>

	</div>
			<div data-options="region:'center',border:false">
			<table id="dataGrid">
			</table>
			<div id="toolbar" style="display: none;">
				<a onclick="genSalesReport();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">查询记录</a>
					<a onclick="downloadExpenseHqDetails();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-print',plain:true">下载账目</a> 
			</div>
		</div>
</div>
								
</body>
</html>